package com.cap5.config;

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;

public class LinCondition implements Condition {
    /**
     * @param conditionContext      判断条件可以使用的上下文环境
     * @param annotatedTypeMetadata 注解的信息
     * @return
     */
    public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
        //TODO 判断是否为WIn系统
        //能获取到IOC容器正在使用的beanFactory
        ConfigurableListableBeanFactory beanFactory = conditionContext.getBeanFactory();
        //获取当前的环境变量（包括我们的操作系统是Win还是Linux）
        Environment environment = conditionContext.getEnvironment();
        String os_name = environment.getProperty("os.name");
        if (os_name.contains("linux")) {
            return true;
        }
        return false;
    }
}
